<template>
  <div class="header-warp">
    <div class="header-content">
      <img src="@assets/cheese2.png" alt="" />
      <div v-if="!isLogin">
        <span class="toLogin" @click="router.push('/login')">登录</span>
        <span class="toRegister" @click="router.push('/register')">注册</span>
      </div>
      <div v-else>
        <span class="toLogin" @click="logout()">登出</span>
      </div>
    </div>
  </div>
  <div class="main-content">
    <!-- 介绍引导巴拉巴拉 <br />
    <n-tag type="primary" class="mt-10 ml-10">OK</n-tag>
    <n-button type="primary">CHEESE</n-button>
    <n-button type="warning">CHEESE</n-button>
    <n-button type="error">CHEESE</n-button>
    <n-button type="success">CHEESE</n-button>
    <n-button type="primary" secondary>123</n-button> -->
    <div class="content-box">
      <div v-if="isLogin" style="margin-bottom: 30px">欢迎回来，{{ name }}</div>
      <div class="text">和全世界的科学家一起做些很酷的事情！</div>
      <n-button
        v-if="!isLogin"
        type="primary"
        size="large"
        @click="router.push('/register')"
      >
        立即注册
      </n-button>
      <n-button
        v-else
        type="primary"
        size="large"
        @click="router.push('/homepage')"
      >
        立即进入
      </n-button>
    </div>
    <div class="outer-img-box">
      <div class="img-box"></div>
    </div>
  </div>
</template>

<script setup>
import api from '@/api/api'

// api访问代理
const { proxy } = getCurrentInstance()
const router = useRouter()
const message = useMessage()

const isLogin = ref(false)
const name = ref('')

const logout = function () {
  api.Entry.logout().then((res) => {
    if (res.success) {
      localStorage.clear()
      message.success('已登出')
      isLogin.value = false
    } else {
      message.error(res.msg)
      localStorage.clear()
    }
  })
}
onMounted(() => {
  api.Entry.islogin().then((res) => {
    if (res.success) {
      name.value = localStorage.getItem('name')
      isLogin.value = true
    } else {
      isLogin.value = false
      localStorage.clear()
    }
  })

  console.log('proxy', proxy.$api)
})

const init = () => {
  // proxy.$api.Entry.login()
}
</script>

<style lang="scss" scoped>
.header-warp {
  height: 72px;
  border-bottom: 1px solid #ddd;
}

.header-content {
  height: 100%;
  width: 70%;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;

  .toLogin {
    margin-right: 15px;
    color: #677469;
    font-weight: 700;
    line-height: 18px;
    font-family: Montserrat, 'sans-serif';
    cursor: pointer;

    &:hover {
      border-bottom: 2px solid;
    }
  }

  .toRegister {
    margin-right: 10px;
    color: #ffa157;
    font-weight: 700;
    line-height: 18px;
    font-family: Montserrat, 'sans-serif';
    cursor: pointer;

    &:hover {
      border-bottom: 2px solid;
    }
  }
}

.main-content {
  padding: 0 0 30px;
  min-height: calc(100vh - 73px);
  width: calc(84% - 48px);
  text-align: left;
  box-sizing: border-box;
  max-width: 1200px;
  margin: 0 auto;
  position: relative;
  height: 90vh;
  display: flex;
  align-items: center;

  &::before {
    content: '';
    position: absolute;
    display: block;
    background-color: #ebefee;
    width: 75vw;
    height: 100%;
    top: 0;
    left: 50%;
    transform: translate(-50vw);
  }

  .content-box {
    z-index: 1;
    font-size: 32px;
    line-height: 38px;
    max-width: 410px;
    font-weight: 700;
    color: #001e1d;
    margin: 0 0 20px;
    text-align: left;
  }

  .n-button {
    padding: 0 150px;
    // .n-button__content::v-deep {
    //   font-size: 42px;
    //   line-height: 24px;
    //   font-weight: 700;
    // }
  }

  .outer-img-box {
    overflow: hidden;
    margin: 40px 0 20px 160px;
    position: relative;
    width: 50%;
    flex-basis: auto;
    z-index: 1;

    .img-box {
      background-image: url(../../assets/he.jpg);
      background-repeat: no-repeat;
      background-position: bottom;
      background-size: cover;
      z-index: 1;
      width: 100%;

      &::after {
        content: '';
        display: block;
        padding-top: 100%;
      }
    }
  }
}
</style>
